﻿using System;
using System.Windows;
using System.Windows.Input;

namespace VipReminder.Controls
{
    /// <summary>
    /// 提示框控件
    /// </summary>
    public partial class MessageBox
    {

        /// <summary>
        /// 禁止在外部实例化
        /// </summary>
        private MessageBox()
        {
            InitializeComponent();
            this.Owner = Application.Current.MainWindow;
        }


        private MessageBoxResult _messageBoxResult = MessageBoxResult.Cancel;


        private void DockContainer_OnDragMove(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        public new string Title
        {
            get { return this.lblTitle.Text; }
            set { this.lblTitle.Text = value; }
        }

        public string Message
        {
            get { return this.lblMsg.Text; }
            set { this.lblMsg.Text = value; }
        }

        private void Yes_OnClick(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            _messageBoxResult = MessageBoxResult.Yes;
            this.Close();
        }


        private void No_OnClick(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            _messageBoxResult = MessageBoxResult.No;
            this.Close();
        }

        public static MessageBoxResult CreateMessageBox(string caption, string msg, MessageBoxButton button = MessageBoxButton.OK)
        {
            MessageBox msgBox = null;
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                msgBox = new MessageBox();
                msgBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                msgBox.Title = caption;
                msgBox.Message = msg;
                SetButtonStatus(msgBox, button);
                msgBox.ShowDialog();
            }));
            return msgBox._messageBoxResult; 
        }

        private static void SetButtonStatus(MessageBox msgBox, MessageBoxButton button)
        {
            switch (button)
            {
                case MessageBoxButton.YesNo:
                    msgBox.BtnNo.Visibility = Visibility.Visible;
                    break;
            }
        }
    }
}
